package com.example.store.controller;


import com.example.store.entity.Order;
import com.example.store.service.IOrderService;
import com.example.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("orders")
public class OrderController extends BaseController{
    @Autowired
    private IOrderService iOrderService;

    @RequestMapping("create")
    public JsonResult<Order> create(Integer aid, Integer[] cids, HttpSession session){
        //Order create(Integer aid, Integer uid, String username, Integer[] cids);

        Integer uid = getUidFromSession(session);
        String username = getUsernameFromSession(session);
        Order data = iOrderService.create(aid, uid, username, cids);
        return new JsonResult<Order>(OK, data);
    }
}
